#include <bits/stdc++.h>
#define int long long
#define rg register
#define pc putchar
#define gc getchar
#define pf printf
#define space pc(' ')
#define enter pc('\n')
#define me(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define FOR(i,k,n,p) for(rg int i(k) ; i <= n ; i += p)
#define ROF(i,k,n,p) for(rg int i(k) ; i >= n ; i -= p)
using namespace std ;
const int N = 12 ;
const int P = 1e6+5 ;
const int MOD = 998244353 ;
int n,k,top ;
int dp[P][N],a[P] ;
inline void read(int &x)
{
	x = 0 ;rg int f(0) ; rg char c(gc()) ;
	while(!isdigit(c)) f |= (c=='-'),c = gc() ;
	while(isdigit(c)) x = (x<<1)+(x<<3)+(c^48),c = gc() ;
	x = (f?-x:x) ;
}
int stk[30],tp ;
inline void print(int x){
	if(x < 0) pc('-'),x = -x ;
	do stk[++tp] = x%10,x /= 10 ; while(x) ;
	while(tp) pc(stk[tp--]^48) ;
}
inline int Made(int pos,int las,int lmt,int lead)
{
	if(pos <= 0) return lead==0 ;
	if(!lead && !lmt && ~dp[pos][las]) return dp[pos][las] ;
	int res = 0,up = lmt?a[pos]:k-1 ;
	FOR(i,las,up,1) res += Made(pos-1,i,lmt&(i==a[pos]),lead&(!i)),res %= MOD ;
	if(!lmt && !lead) dp[pos][las] = res ;
	return res ;
}
inline int Solve()
{
	top = n ;
	return Made(top,0,1,1) ;
}
signed main()
{
	freopen("count.in","r",stdin) ;
	freopen("count.out","w",stdout) ;
	me(dp,-1),read(n),read(k) ;
	FOR(i,1,n,1) read(a[i]) ;
    reverse(a+1,a+1+n) ;
	print(Solve()) ;
	return 0 ;
}